package com.cloudwise.monitoring_system.controller.mysqlController;

import com.cloudwise.monitoring_system.entity.MonitorValue;
import com.cloudwise.monitoring_system.service.mysqlService.MonitorValueService;
import com.cloudwise.monitoring_system.util.Result;
import com.cloudwise.monitoring_system.util.ReturnStatus;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;

/**
 * (MonitorValue)表控制层
 *
 * @author makejava
 * @since 2021-05-19 15:52:21
 */
@Controller
@RequestMapping("monitor")
@ApiOperation("mysql监控项数据控制器")
public class MonitorValueController {
    /**
     * 服务对象
     */
    @Resource
    private MonitorValueService monitorValueService;
    /**
     * 通过实体作为筛选条件查询
     *
     * @return 对象列表
     */
    @ResponseBody
    @GetMapping("queryAll")
    @ApiOperation("查询所有监控项数据结果")
    public Result queryAll(@ApiParam("监控项数据")MonitorValue monitorValue) {
        return new Result(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(),
                0,this.monitorValueService.queryAll(monitorValue));
    }

    /**
     * 新增数据
     *
     * @param monitorValue 实例对象
     * @return 实例对象
     */
    @ResponseBody
    @PostMapping("insert")
    @ApiOperation("新增一条监控项数据")
    public Result insert(@ApiParam("监控项数据")MonitorValue monitorValue) {
        return new Result(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(), 0,
                this.monitorValueService.insert(monitorValue));
    }

    /**
     * 通过unitId查询监控项数据
     * @param unitId
     * @return
     */
    @ResponseBody
    @PostMapping("queryByUnitId")
    @ApiOperation("通过unitId查询监控项数据")
    public Result queryByUnitId(@ApiParam("监控项数据unitId")Integer unitId) {
        return new Result(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(), 0,
                this.monitorValueService.queryByUnitId(unitId));
    }

}
